home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / SAT Invaders demo ƒ / sPlayer.p < prev    next >
Text File  |  1994-11-02  |  3KB  |  107 lines

  1. {===============================================}
  2. {================= Player sprite unit ================}
  3. {===============================================}
  4.  
  5. { Example file for Ingemars Sprite Animation Toolkit. }
  6. { © Ingemar Ragnemalm 1992 }
  7. { See doc files for legal terms for using this code. }
  8.  
  9. { This file is the first of several sprite units, units that holds the full}
  10. {description of the objects to be animated. }
  11.  
  12. unit sPlayer;
  13.  
  14. { Sprite unit. A sprite unit should include the following routines:}
  15. { Init-procedure, that initializes private bitmaps}
  16. { Setup-procedure, that sets variables other than the standard ones set by MakeSprite }
  17. { Handle-procedure, to be called once per iteration until the sprite dies }
  18. { Hittask-procedure (optional), for advanced collission handling. }
  19.  
  20. { This is the sprite unit for the player object, in this case a cannon. }
  21.  
  22. interface
  23.  
  24.     uses
  25. {$IFC UNDEFINED THINK_PASCAL}
  26.         Types, QuickDraw, Events, ToolUtils, {}
  27. {$ENDC}
  28.         GameGlobals, SAT, SoundConst, sShot;
  29.  
  30.     var
  31.         stillRunning: boolean;
  32.  
  33.     procedure InitPlayer;
  34.     procedure SetupPlayer (player: SpritePtr);
  35.     procedure HandlePlayer (me: SpritePtr);
  36.  
  37. implementation
  38.  
  39.     const
  40.         playerspeed = 16; {How fast may the player object move per frame, max?}
  41.  
  42.     var
  43.         playerFace: FacePtr;
  44.  
  45.     procedure InitPlayer;
  46.     begin
  47.         playerFace := SATGetFace(134); {Preload the player face (from cicn resource)}
  48.     end;
  49.  
  50.     procedure SetupPlayer (player: SpritePtr);
  51.     begin
  52.         player^.face := playerFace;
  53.         SetRect(player^.hotRect, 1, 7, 31, 32);
  54.         player^.task := @HandlePlayer;
  55.     end;
  56.  
  57.     procedure HandlePlayer (me: SpritePtr);
  58.         var
  59.             pt: point;
  60.             shot: SpritePtr;
  61.     begin
  62. {We detect collisions with change in "kind". We could also have chosen to do this}
  63. {with a "hitTask", a callback proceure.}
  64.         if me^.kind <> 2 then
  65.             begin
  66.                 SATSoundPlay(kraschH, 10, true);        {Play a sound}
  67.                 stillrunning := false;                        {Tell MoveIt that the game is over, to quit the game loop.}
  68. { Real games make an explosion before quitting!}
  69.             end;
  70.  
  71. {Where is the mouse pointer?}
  72.         SATSetPortScreen;
  73.         GetMouse(pt);
  74.  
  75.         me^.speed.h := pt.h - me^.position.h; {How far from the previous position?}
  76.  
  77. {Change the position to the new position, but not by more than platerspeed!}
  78.         if me^.speed.h < -playerspeed then
  79.             me^.position.h := me^.position.h - playerspeed
  80.         else if me^.speed.h > playerspeed then
  81.             me^.position.h := me^.position.h + playerspeed
  82.         else
  83.             me^.position.h := me^.position.h + me^.speed.h;
  84.  
  85. {Make sure we don't go out of sight.}
  86.         if me^.position.h > gSAT.offSizeH - 32 then
  87.             begin
  88.                 me^.position.h := gSAT.offSizeH - 32;
  89.             end;
  90.         if me^.position.h < 0 then
  91.             begin
  92.                 me^.position.h := 0;
  93.             end;
  94.  
  95. { Create shots }
  96.         if me^.mode > 0 then
  97.             me^.mode := pred(me^.mode);
  98.         if me^.mode = 0 then {We may only shoot every 10 frames!}
  99.             if Button then
  100.                 begin
  101.                     shot := SATNewSprite(1, me^.position.h + 12, me^.position.v, @SetupShot);
  102.                     me^.mode := 10;
  103.                     SATSoundPlay(toffH, 1, false);
  104.                 end;
  105.     end;
  106.  
  107. end.